package com.mentaleye.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.bean.TimeTableClassBean;
import com.mentaleye.dal.dao.TimeTableClassDao;
import com.mentaleye.dal.model.TimeTableClass;
import com.mentaleye.dal.model.TimeTableClassExample;
import com.mentaleye.dal.model.TimeTableClassKey;
import com.mentaleye.service.TimeTableClassService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.ObjectUtil;

@Service
public class TimeTableClassServiceImpl implements TimeTableClassService{

	@Autowired private TimeTableClassDao timeTableClassDao;
	
	@Override
	public boolean addTimeTableClass(TimeTableClassBean timeTableClassBean){
		timeTableClassBean.setCreatTime(new Date());
		TimeTableClass timeTableClass = (TimeTableClass) ObjectUtil.transfer(timeTableClassBean, TimeTableClass.class);
		return timeTableClassDao.insert(timeTableClass);
	}
	
	@Override
	public boolean updateTimeTableClass(TimeTableClassBean timeTableClassBean){
		TimeTableClass timeTableClass = (TimeTableClass) ObjectUtil.transfer(timeTableClassBean, TimeTableClass.class);
		return timeTableClassDao.update(timeTableClass);
	}
	
	@Override 
	public boolean deleteTimeTableClass(int timeTableId,int oaClassId){
		TimeTableClassKey key = new TimeTableClassKey();
		key.setTimeTableId(timeTableId);
		key.setOaClassId(oaClassId);
		return timeTableClassDao.delete(key);
	}
	
	@Override
	public boolean deleteTimeTableClassList(List<TimeTableClassKey> keylist){
		return timeTableClassDao.deleteList(keylist);
	}
	
	@Override
	public TimeTableClassBean queryTimeTableClassByKey(int timeTableId,int oaClassId){
		TimeTableClassKey key = new TimeTableClassKey();
		key.setTimeTableId(timeTableId);
		key.setOaClassId(oaClassId);
		return (TimeTableClassBean) ObjectUtil.transfer(timeTableClassDao.selectByKey(key), TimeTableClassBean.class);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<TimeTableClassBean> queryTimeTableClassByExample(TimeTableClassExample example){
		return ObjectUtil.transferList(timeTableClassDao.selectByExample(example), TimeTableClassBean.class);
	}
	
	@Override
	public void queryByMap(CommonPage commonPage){
		List<TimeTableClass> data = timeTableClassDao.selectByMap(commonPage.pageToMap());
		commonPage.setPageData(data);
	}
}
